<?php
header('content-type: text/html; charset=utf-8');
session_start();
include('../config.php'); 

if(!isset($_SESSION['ID']) && (!isset($_POST["userid"]) || $_POST["userid"]==""))
{
	echo "<script type = 'text/javascript'>";
	echo "window.location = '../login/login-error.php';";
	echo "</script>";
}
else if(isset($_SESSION['ID']))
{
	echo "<script type = 'text/javascript'>";
	echo "window.location = '../detail/index.php';";
	echo "</script>";
}
else
{
	LinkDataBase();
	$sql = "select * from member where id= '".$_POST["userid"]."' ";
	$result= mysql_query($sql);

	while($row = mysql_fetch_assoc($result))
	{
		$id = $row['id'];
		$pw = $row['password'];
	}
	
	
	if($id == $_POST['userid'] && $pw == $_POST['userpw'] && mb_strlen($pw,'utf8') == mb_strlen($_POST['userpw'],'utf8'))
	{
		if(!isset($_SESSION['ID']))
		{	
			$_SESSION['ID']=$_POST['userid'];
			echo "<script type = 'text/javascript'>";
			echo "window.location = '../detail/index.php';";
			echo "</script>";
		}			
	}
	else
	{
		echo "<script type = 'text/javascript'>";
		echo "window.location = '../login/login-error.php';";
		echo "</script>";
	}
}

?>
